package com.yunji.web.base;

import com.yunji.base.business.AllianceBusiness;
import com.yunji.base.domain.AllianceDO;
import com.yunji.base.vo.AllianceDTO;
import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.web.user
 * @FileName AllianceController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-02 13:50:12
 * @Description 代理商加盟交互
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-02 13:50:12		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Api(tags = "管理端-代理商加盟")
@RestController
@RequestMapping("/container/alliance")
public class AllianceController extends BaseController {

    @Resource
    AllianceBusiness business;


    /**
     * 查询加盟列表
     */
    @ApiOperation("查询加盟列表")
    @PreAuthorize("@ss.hasPermi('container:alliance:query')")
    @GetMapping("/list")
    public Response<List<AllianceDTO>> list(@Valid AllianceDTO alliance) {
        List<AllianceDTO> list = business.selectSAllianceDTOList(alliance);
        return ResponseHelper.successWithPage(list);
    }

    /**
     * 导出加盟列表
     */
    @ApiOperation("导出加盟列表")
    @Log(title = "加盟", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AllianceDTO allianceDTO) {
        List<AllianceDTO> list = business.selectSAllianceDTOList(allianceDTO);
        ExcelUtil<AllianceDTO> util = new ExcelUtil<>(AllianceDTO.class);
        util.exportExcel(response, list, "加盟数据");
    }

    /**
     * 获取加盟详细信息
     */
    @ApiOperation("获取加盟详细信息")
    @GetMapping(value = "/{id}")
    public Response<AllianceDO> getInfo(@PathVariable("id") Long id) {
        return ResponseHelper.success(business.selectSAllianceById(id));
    }

    /**
     * 新增加盟
     */
    @ApiOperation("新增加盟")
    @Log(title = "加盟", businessType = BusinessType.INSERT)
    @PostMapping
    public Response<Long> add(@RequestBody AllianceDO sAlliance) {
        return ResponseHelper.success(business.insertSAlliance(sAlliance));
    }

    /**
     * 修改加盟
     */
    @ApiOperation("修改加盟")
    @Log(title = "加盟", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('container:alliance:edit')")
    @PutMapping
    public Response<String> edit(@RequestBody AllianceDO sAlliance) {
        business.updateSAlliance(sAlliance);
        return ResponseHelper.success();
    }

    /**
     * 删除加盟
     */
    @ApiOperation("删除加盟")
    @Log(title = "加盟", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Response<String> remove(@PathVariable Long[] ids) {
        business.deleteSAllianceByIds(ids);
        return ResponseHelper.success();
    }

    /*---------------------------------搜索栏---------------------------*/

    @ApiOperation("加盟商姓名匹配搜索")
    @GetMapping("/searchName")
    public Response<List<String>> searchName(@RequestParam("name") String name) {
        return ResponseHelper.successWithPage(business.searchName(name));
    }

    @ApiOperation("手机号码匹配搜索")
    @GetMapping("/searchPhone")
    public Response<List<String>> searchPhone(@RequestParam("phone") String phone) {
        return ResponseHelper.successWithPage(business.searchPhone(phone));
    }

}
